﻿using LanguagePolish.EntityModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LanguagePolish.Models
{
    class ClassroomsModel
    {
        public bool CanUserAddClassrooms
        {
            get
            {
                return LinksProvider.Model.CurrentUser.AccountType.AddPermission == true;    
            }
        }

        //public bool CanUserEditClassroom { get; set; }

        public bool CanUserRemoveClassrooms
        {
            get { return LinksProvider.Model.CurrentUser.AccountType.DeletePermission == true; }
        }

        public bool CanUserEditClassrooms
        {
            get { return LinksProvider.Model.CurrentUser.AccountType.EditClassroomsPermissions == true; }
        }

        public IEnumerable<Classroom> GetClassrooms()
        {
            var context = LinksProvider.Model.EntityContext;
            var res = context.Classrooms.ToList();
            return res;
        }

        public void AddClassroom(Classroom classroom)
        {
            var context = LinksProvider.Model.EntityContext;
            context.Classrooms.Add(classroom);
            context.SaveChanges();
        }

        public void RollbackClassroom(Classroom classroom)
        {
            var context = LinksProvider.Model.EntityContext;
            context.Rollback(classroom);
        }

        public void SaveChanges()
        {
            LinksProvider.Model.EntityContext.SaveChanges();
        }

        public void DeleteClassroom(Classroom classroom)
        {
            var context = LinksProvider.Model.EntityContext;
            context.Classrooms.Remove(classroom);
            context.SaveChanges();
        }

    }
}
